package me.zhengjie.modules.system.domain

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import cn.hutool.core.util.ObjectUtil
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import me.zhengjie.modules.system.service.dto.DictDTO

import jakarta.persistence.*
import org.apache.commons.lang3.builder.ToStringBuilder
import org.hibernate.annotations.CreationTimestamp
import org.springframework.data.redis.core.RedisHash
import java.sql.Timestamp



/**
 * @author Kuki Wu
 * @date 2019年9月7日 16:16:59
 */
@Entity
@Table(name = "sys_user_avatar")
@JsonTypeName("UserAvatar")
@RedisHash("useravatar")
data class UserAvatar(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null,

    var realName: String? = null,

    var path: String? = null,

    var  size: String? = null,

    @Column(name = "create_time")
    @CreationTimestamp
    var createTime: Timestamp? = null

){
    annotation class Update

    companion object {
        fun fromJson(json: String): UserAvatar? {
            val obj = JacksonUtil.parseObject(json, UserAvatar::class.java)!!
            return when (obj) {
                is UserAvatar -> obj
                else -> null
            }
        }
    }

    fun tojson(): String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source:UserAvatar?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}
